#!/usr/bin/env python
#
import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from models import Video
import re


class MainHandler(webapp.RequestHandler):
	def get(self, data=None):
		path = os.path.join(os.path.dirname(__file__), 'index.html')
		self.response.out.write(template.render(path,data))


class Videosend(webapp.RequestHandler):
	def post(self, data=None):
		videourl = self.request.get('label-0_field')
		videomessage = self.request.get('textarea_field')
		i = videourl.split("?v=")
		videoid=i[1]
		v = Video()
		v.videoid=videoid
		v.videomessage=videomessage
		v.put()
		path = os.path.join(os.path.dirname(__file__), 'thanks.html')
		self.response.out.write(template.render(path,data))
 

application = webapp.WSGIApplication([('/', MainHandler),('/send', Videosend)], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

